package com.yidu.controller;

import com.yidu.entity.AmModule;
import com.yidu.service.AmModuleService;
import com.yidu.utils.BaseMessage;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * 模块表(AmModule)表控制层
 *
 * @author wanghong
 * @since 2021-08-02 11:48:26
 */
@RestController
@RequestMapping("amModule")
public class AmModuleController {
    /**
     * 服务对象
     */
    @Autowired
    private AmModuleService amModuleService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public AmModule selectOne(Integer id) {
        return this.amModuleService.queryById(id);
    }

    /**
     * 增加模块
     * @param amModule
     * @return
     */
    @RequestMapping("addAndUpdate")
    @ResponseBody
    public Map<String,Object> addAndUpdate(AmModule amModule){
        if (amModule.getModuleId()==null){
            AmModule insert = amModuleService.insert(amModule);
            if (amModule.getAm_ModuleId()==null){
                insert.setAm_ModuleId(insert.getModuleId());
                AmModule update = amModuleService.update(insert);
            }

            return BaseMessage.judge("1","增加成功");
        }else {
            AmModule update = amModuleService.update(amModule);

            return BaseMessage.judge("1","修改成功");
        }

    }



}
